/* eslint-disable @typescript-eslint/no-explicit-any */
import type { ActionType } from '@ant-design/pro-components';

// common
export enum EHttpMethod {
    PUT = 'put',
    GET = 'get',
    POST = 'post',
    PATCH = 'patch',
    DELETE = 'delete',
}
export type HttpMethod = `${EHttpMethod}`;

export type CommmonFormatter<D> = (data: any) => D | Record<string, never>;
export type ApiItem = {
    url: string;
    method: HttpMethod;
    name?: string;
    isForm?: boolean;
    urlConfig?: UrlConfig;
};

export type TreeApis = {
    get: ApiItem;
    detail?: ApiItem;
    add: ApiItem;
    update: ApiItem;
    delete: ApiItem;
    updateNo?: ApiItem;
};

// fuc
export enum ModelDataMode {
    CREATE = 'create',
    UPDATE = 'update',
}
export enum ActionPlacement {
    IN_TOOLBAR = 'in_toolbar',
    IN_TABLE = 'in_table',
    IN_DRAWER = 'in_drawer',
}
export const ModelDataMode2IntlKeyOrDsl: Type2IntlKeyOrDsl<ModelDataMode> = {
    [ModelDataMode.CREATE]: 'CREATE__TARGET',
    [ModelDataMode.UPDATE]: 'UPDATE__TARGET',
};

export interface TModelDataContainerProps<Mode = ModelDataMode> extends CommonProps {
    mode: Mode;
}

export interface TModelContainerProps<Form> extends CommonProps {
    actionRef: React.MutableRefObject<ActionType | undefined>;
    title?: string | React.ReactNode;
    loading?: boolean;
    setData: UnknonReturnFuc<[Form]>;
    request: UnknonReturnFuc<[any?]>;
}

export interface TModelFormContainerProps<Form, Mode = ModelDataMode, Model = any, Placement = ActionPlacement>
    extends TModelContainerProps<Form> {
    mode: Mode;
    placement?: Placement;
    isMultiple?: boolean;
    data?: Model | Form;
    initialValues?: Form;
    open?: boolean;
}

export interface TActionContainerProps<Form, Mode, Row, Model = any>
    extends TModelFormContainerProps<Form, Mode, Model> {
    rowData?: Row;
    formIndex?: keyof Form;
    checkIsDisabled?: (record?: Row) => boolean;
    danger?: boolean;
}

export interface PageQuery<T = any> {
    current?: number;
    size?: number;
    search?: string;
    param?: {
        [P in keyof T]?: T[P];
    };
}

export interface Result<T = any> {
    msg: string;
    code: number;
    data: T;
    success: boolean;
}
export interface TableList<T> {
    records: T[];
    total: number;
}

type Type2IntlKeyOrDsl<T extends keyof any> = { [key in T]: string };

export enum ELoginType {
    PASSWORD = 'password',
    PHONE = 'phone',
}
export type LoginType = `${ELoginType}`;

export enum ELoginMode {
    MESSAGE = 'message',
    QR_CAPCHA = 'qrCapcha',
}
export type LoginMode = `${ELoginMode}`;

// role 角色
export enum EAuthority {
    ADMINISTRATOR = 'administrator',
}

// modules
export enum ENodeRole {
    COMPUTE = 'compute',
    NETWORK = 'network',
    MANAGER = 'manager',
    MASTER = 'master',
    WORKER = 'worker',
}
export type NodeRole = `${ENodeRole}`;
export const NodeRole2IntlKeyOrDsl: Type2IntlKeyOrDsl<ENodeRole> = <const>{
    [ENodeRole.COMPUTE]: 'NODE_COMPUTE',
    [ENodeRole.NETWORK]: 'NODE_NETWORK',
    [ENodeRole.MANAGER]: 'NODE_MANAGER',
    [ENodeRole.MASTER]: 'NODE_MASTER',
    [ENodeRole.WORKER]: 'NODE_WORKER',
};

export enum ENodeType {
    PHYSICAL = 'physical',
    VIRTUAL = 'virtual',
    CONTAINER = 'container',
}
export type NodeType = `${ENodeType}`;
export const NodeType2IntlKeyOrDsl: Type2IntlKeyOrDsl<NodeType> = <const>{
    [ENodeType.PHYSICAL]: 'NODE_PHYSICAL',
    [ENodeType.VIRTUAL]: 'NODE_VIRTUAL',
    [ENodeType.CONTAINER]: 'NODE_CONTAINER',
};
